<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo  Q::ini('appini/app_title')." ". Q::ini('appini/version');?></title>
<link href="css/default.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="js/jquery-easyui/themes/default/easyui.css"/>
<link rel="stylesheet" type="text/css" href="js/jquery-easyui/themes/icon.css"/>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery-easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="js/jquery-easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>

<script language="javascript">
function searchmember(){  
    $('#dlgSearch').dialog('open').dialog('setTitle','查找');  
}

function doSearch(){
	
	alert($("#dlgSearch").form('validate'));
	return false;
	if($("#frmSearch").form('validate')){
		return false;	
	}
	site_id=$("#site_id").combobox('getValue');
	agent_id=$("#agent_id").combobox('getValue');
	
	
	$("#dg").datagrid({ url: '<?=url('member/list')?>', queryParams: { site_id: site_id,agent_id:agent_id} });
	
	$('#dlgSearch').dialog('close');
} 

$(function(){
	$('#dg').datagrid({
		title:'返水操作',
		iconCls:'icon-save',
		width:500,
		height:350,
		fit: true,
		nowrap: true,
		autoRowHeight: true,
		striped: true,
		collapsible:true,
		url:'<?=url('cashback/list')?>',
		sortName: 'name',
		sortOrder: 'desc',
		remoteSort: false,
		idField:'member_id',
		columns:[[
			{field:'site',title:'站点',width:100},
			{field:'agent',title:'代理',width:100},
			{field:'name',title:'真实姓名',width:100},
			{field:'username',title:'会员帐号',width:100},
			{field:'bank',title:'银行名称',width:100},			
			{field:'phone',title:'联系电话',width:100},
			{field:'opt',title:'返水金额',width:100,align:'center',
				formatter:function(value, rec,rowIndex){
					_id = 'amount['+rec.member_id+']';
					row = "<input class='amount' type='text' size='5' name='"+ _id +"' id='" + _id + "' />";
					return row;
				}
			}
		]],
		pagination:true,
		rownumbers:true,
		toolbar:[{
			id:'btnrefresh',
			text:'刷新',
			iconCls:'icon-reload',
			handler:function(){
				//alert("刷新");
				$('#dg').datagrid('reload');
				
			}
		},
		'-',
		{
			id:'btnsearch',
			text:'查找',
			iconCls:'icon-search',
			handler:function(){
				searchmember();				
			}
		},
		'-',
		{
			id :'btnsave',
			text: ' 提 交 ',
			iconCls: 'icon-save',
			handler:function(){
				save();	
			}	
		}
	]
	});
	
});



function save(){
	var total=0.00;
	$(".amount").each(function(i,o){
		total=total+parseFloat($(this).val());
	});	
	
	
	
	message="<div style='float:left;'>请确认以下信息是否正确：<br><br>"
		+"代理：" + $("#agent_id").combobox('textbox').val()
		+ "<br>返水总金额：" + total
		+ "<p>&nbsp;</p></div>";
	$.messager.confirm('确认', message, function(r){
		if (r){
			data=$(".amount").serialize()+"&agent_id="+$("#agent_id").combobox('getValue');
			$.ajax({
				type: "POST",
				dataType:"json",
				url: "<?=url('cashback/save')?>",
				data: data,
				beforeSend: function(){
					$.messager.progress({title:"进度",msg:'操作正在进行中，请稍后..'});
				},
				success: function(msg){
					if(msg.success == 'ok'){
						$.messager.progress('close');
						$.messager.show({
							'title': "提示",
							'msg': "操作完成."	
						});	
					}
					else{
						$.messager.progress('close');
						$.messager.show({
							'title': "提示",
							'msg': msg.errorMsg	
						});		
					}
			   }
			}); 
		} //end if
	}); //end $messager.confirm()
}
</script>


</head>

<body class="easyui-layout" style="overflow-y: hidden" scroll="no">
    
    <div region="center" style="width: 500px; height: 300px; padding: 1px;overflow-y: hidden">      
    	
       <table id="dg"></table>        
       
    </div>	
    
    <!--search box-->
    <div id="dlgSearch" class="easyui-dialog" style="width:400px;height:200px;padding:10px 20px" closed="true" buttons="#dlgSearch-buttons"  modal="true"> 
        <form method="post" id="frmSearch">
            <table>
                <tr>
                <td height="30">站点：</td>
                <td>
                <input class="easyui-combobox easyui-validatebox" required="required" id="site_id" name="site_id"  
                    data-options="valueField:'site_id',textField:'name',onSelect: function(rec){  
                        var url = '<?=url('agent/list')?>&site_id=' + rec.site_id;  
                        $('#agent_id').combobox('reload', url);  
                    }" url='<?=url("site/list")?>'
                      />  
                </td>
                </tr>
                <tr>
                <td height="30">代理：</td>
                <td><input name="agent_id" id="agent_id" class="easyui-combobox easyui-validatebox" required="required" data-options="valueField:'agent_id',textField:'name'"  />
                </td>
                </tr>
            </table>
        </form>
    </div>
    <div id="dlgSearch-buttons">  
        <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="doSearch()">搜索</a>  
        <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlgSearch').dialog('close')">取消</a>  
    </div>  
        
</body>
</html>